package dmeo.spring.cloud.eureka.provider;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by lushun.chen on 2017/4/6.
 *
 * @author lushun.chen
 */
@RestController
@RequestMapping("")
public class UserController {
    @Autowired
    private DiscoveryClient discoveryClient;
    @Autowired
    private UserRepository userRepository;

    // @GetMapping("/id")
    @RequestMapping("/{id}")
    public User findById(@PathVariable Long id) {
        System.out.println(id);
        User user = new User();
        user.setAge(12);
        user.setId(1L);
        return this.userRepository.findOne(id);
    }

    // @GetMapping("/instance_info")
    @RequestMapping("instance_info")
    public ServiceInstance showInfo() {
        ServiceInstance localServiceIntance = this.discoveryClient.getLocalServiceInstance();
        return localServiceIntance;
    }


}
